#!/usr/bin/perl -w
use strict;
### print all the regex_scans
if(scalar(@ARGV) < 1) { die "./print_hits.pl regex_id\n"; }
my $regex_id = shift(@ARGV);
my $outputfile = '';
if(scalar(@ARGV) > 0) { $outputfile = shift(@ARGV); }
my $command = 'mysql zebraphish -e "SELECT chromosome, hit_start, hit_finish, sequence FROM hits JOIN chromosome_scan ON hits.chromosome_scan_id = chromosome_scan.db_id JOIN regex_scan ON chromosome_scan.regex_id = regex_scan.db_id AND regex_scan.db_id = ' . $regex_id . ' ORDER BY chromosome, hit_start, hit_finish"';
chomp(my @lines = `$command`);
if($outputfile eq '') {
  foreach my $line (@lines) { print "$line\n"; }
} else {
  open(FH,">$outputfile") or die "couldn't open $outputfile sorry.\n";
  foreach my $line (@lines) { print FH "$line\n"; }
  close FH;
}
